﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Google_Authenticator_netcore;

namespace Topro.Admin.Controllers
{
    using Topro.Application.Interface;
    using Topro.Entity.Request.User;
    

    /// <summary>
    /// 首页
    /// </summary>
    public class HomeController : BaseController
    {
        #region 注入
        /// <summary>
        /// 权限接口
        /// </summary>
        private readonly AuthService _authService;

        /// <summary>
        /// 权限接口
        /// </summary>
        private readonly LoginService _loginService;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="authService">权限接口</param>
        public HomeController(AuthService authService, LoginService loginService)
        {
            _authService = authService;
            _loginService = loginService;
        }
        #endregion

        /// <summary>
        /// 后台管理
        /// </summary>
        /// <returns>视图</returns>
        public IActionResult Index()
        {
            //用户名
            ViewBag.UserName = this.UserName;
            //用户菜单
            var menus = _loginService.GetMenus(this.UserId);

            return View(menus);
        }

        /// <summary>
        /// 后台管理
        /// </summary>
        /// <returns>视图</returns>
        public IActionResult Main()
        {
            return View();
        }

        /// <summary>
        /// 用户[重置]
        /// </summary>
        /// <returns></returns>
        public IActionResult ResetPassWord()
        {
            var viewName = "~/Views/Home/ResetPassWord.cshtml";

            var model = _authService.GetUser(UserId);

            return View(viewName, model);
        }

        /// <summary>
        /// 修改密码
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public JsonResult ResetPassWord(ResetPassWordRequest request)
        {
            request.Id = UserId;

            var response = _authService.ResetPassWord(request);

            return Json(response);
        }
    }
}
